import validate from 'wechat-validate'
Page({
  data:{
    showCaptcha:false,
    password:'123456',
    account:'xbsj001',
  },
  onLoad({redirectURL}){
    this.redirectURL = redirectURL
  },
  rules: {
    account: [
      {required: true, message: '账号错误,请重新输入!'},
      {pattern: /^[a-zA-Z]\w{4,15}$/, message: '请填写正确的账号!'}
    ],
    password: [
      { required: true, message: '密码错误,请重新输入!' },
      { pattern: /^\d{6}$/, message: '请检查密码是否正确!' }
    ]
  },
  behaviors: [validate],
  toggleDate:function(){
      this.setData({
        showCaptcha:!this.data.showCaptcha,
      })
  },
  // 调用数据接口的方法
  async getBooks() {
    const isAllValid = this.validate()
    // 调用小程序的 API 发起请求
    if (!isAllValid) {
      wx.$toast('表单验证失败')
      return
    }
    const {account,password} = this.data
    const data = await wx.$http.post('/driver/login/account',{account,password})
    // console.log(data)
    const app = getApp()
    app.setToken('token',data)
    // 跳转
    const url =this.redirectURL || '/pages/index/index'
    wx.switchTab({url})
  }
})